<template>
    <view>
		<u-navbar height="60" bgColor="#0081ff">
			<!-- #ifdef MP-WEIXIN -->
			<view class="u-nav-slot margin-top-xl" slot="left">
			</view>
			<!-- #endif -->
			<view slot="center" class="u-nav-slot">
				<view style=" font-size: 20px; color: #FFFFFF;">定时任务</view>
			</view>
		</u-navbar>
      <!--  <cu-custom bgColor="bg-blue" :isBack="true" >
            <block slot="backText"></block>
            <block slot="content">{{device.deviceName}} 定时管理</block>
        </cu-custom> -->
		
        <view class="cu-list menu card-menu margin-top xl-border" :class="item.status==1?'my-border': ''" v-for="(item,index) in taskList" :key="index">
            <view class="cu-item" @tap="editTask(item.jobId)">
                <view class="content flex align-center">
                    <view class="flex margin-left-sm">{{item.buttonName}}</view>
                    <view class="flex flex margin-left-sm flex-wrap">
                        <text class="text-grey">{{item.week}}</text>
                        <text class="text-grey margin-left-sm">{{item.time}}</text>
                    </view>
                </view>
                <view class="text-blue">{{item.instruct == "open" ? '开启':'关闭'}}</view>
            </view>
        </view>

        <view class="flex  justify-center cu-bar tabbar bg-white shadow foot" @tap="addTask">
            <view class="text-blue cuIcon-add text-xl">添加定时</view>
        </view>
    </view>
</template>

<script>
    import {
        isMobile
    } from '@/util/validate'
    export default {
        data() {
            return {
                taskList: null,
                device: {
                    deviceId: null,
                    deviceName: null
                },
            }
        },
        onLoad(option) {
            this.device.deviceId = option.deviceId
            this.device.deviceName = option.deviceName
            this.getTaskList()
            this.getInfo()
        },
        onShow() {
            this.getTaskList()
        },
        methods: {
            //跳转到添加定时任务页面
            addTask() {
                uni.navigateTo({
                    url: './addTask?deviceId=' + this.device.deviceId
                })
            },
            editTask(jobId){
               uni.navigateTo({
                   url:'./editTask?jobId='+jobId
               }) 
            },
            //获取设备对应的定时任务
            getTaskList() {
                this.$http.request({
                    url:  'app/task/listByDeviceId',
                    method: 'GET',
                    data: {
                        'deviceId': this.device.deviceId
                    },
                    success: (data) => {
                        if (data.data && data.data.code == 0) {
                            this.taskList = data.data.list
                        }
                    }
                })
            },
            getInfo(){
                this.$http.request({
                    url:  'app/device/info/' + this.device.deviceId,
                    method: 'GET',
                    success: (data) => {
                        if (data.data && data.data.code == 0) {
                            this.device = data.data.device
                        }
                    }
                })
            },
        }
    }
</script>

<style>
    .my-border{
        border-bottom: #ff4245 solid 0.3vh;
    }
</style>
